#!/bin/sh
ip=10.20.187.232
port=843
python=/usr/bin/python

function_start() 
{
    printf "Cooper Server Start\n"
    nohup ${python} run.py -p ${port} -i ${ip}  &
}

function_stop()
{
   printf "Cooper Server Stop\n"
   kill -9 $(ps -ef | grep "python" | grep "run.py" | grep -v "grep" | awk -F ' ' '{print $2}')
   rm -rf nohup.out
}

function_restart()
{
   printf "Cooper Server ReStart\n"
   function_stop
   function_start
}

if [ "$1" = "start" ] || [ "$1" = "s" ]; then
   function_start
elif [ "$1" = "stop" ] || [ "$1" = "t" ]; then
   function_stop
elif [ "$1" = "restart" ] || [ "$1" = "r" ]; then
   function_restart
else
    printf "Usage: run.sh {start|stop|restart}\n"
    printf " r = restart\n s = start\n t = stop\n"
fi
